package 多线程.Test;

public class Test04 {
    public static void main(String[] args) {
        //普通线程跟精灵线程对比
        Thread t1 = new CommonThread();
        //新建任务，在绑定到一个线程上
        Thread t2 = new Thread(new MyDaemon());
        //设置守护线程
        t2.setDaemon(true);
        t2.start();
        t1.start();

    }
}
//线程
class CommonThread extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 50; i++) {
            System.out.println("用户线程第" + i + "次执行");
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
//精灵线程  任务类
class MyDaemon implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println("守护线程第" + i + "次执行");
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}